home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / psend.arc / PSEND.ASM < prev    next >
Assembly Source File  |  1987-09-29  |  7KB  |  195 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                       ;;
  3. ;;   PSEND.ASM    Last modified: 09/29/87    R. Trevithick    MASM 4.0   ;;
  4. ;;-----------------------------------------------------------------------;;
  5. ;;           Send printer codes from ascii control code files.           ;;
  6. ;;                                                                       ;;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. BSIZE   equ     07fffh                          ; 32K buffer should do it!
  10.  
  11.  
  12.  
  13. PRT     SEGMENT PARA PUBLIC 'CODE'              ; some info for the assembler
  14.         ASSUME  CS:PRT, DS:PRT
  15.         ORG     0100h
  16.  
  17.  
  18. start:  cmp     byte ptr ds:[80h], 1            ; any parameters?
  19.         jg      parm
  20.         mov     al, 1
  21.         jmp     exit
  22.  
  23. parm:   mov     si, 82h
  24. parm2:  cmp     byte ptr ds:[si], 0dh
  25.         jne     parm3
  26.         mov     byte ptr ds:[si], 0             ; insert zero byte for DOS
  27.         jmp     short open
  28. parm3:  inc     si
  29.         jmp     short parm2
  30.  
  31. open:   mov     dx, 82h                         ; point to filespec in PSP
  32.         mov     ax, 3d00h                       ; try to open for read-only
  33.         int     21h
  34.         jnc     read
  35.         mov     al, 1
  36.         jmp     exit
  37.  
  38. read:   mov     bx, ax                          ; get handle into bx
  39.         mov     dx, offset ds:buffer            ; point to the buffer
  40.         mov     ah, 03fh                        ; read service
  41.         mov     cx, BSIZE                       ; size of read buffer
  42.         int     21h
  43.         jnc     read2
  44.         mov     al, 1
  45.         jmp     exit
  46.  
  47. read2:  cmp     ax, 0                           ; special case, 0 byte file
  48.         jne     read3
  49.         mov     al, 1
  50.         jmp     exit
  51.  
  52. read3:  cmp     ax, BSIZE                       ; see if too large a file
  53.         jb      disp
  54.         mov     al, 1
  55.         jmp     exit
  56.  
  57. ;
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59. ; here's where the work get's done
  60. ;
  61. ; bh = parser flag, bl = strlen
  62. ;
  63.  
  64. disp:   mov     cx, ax                          ; bytes read into loop counter
  65.  
  66.         call    pr_chk                          ; check the printer
  67.  
  68.         xor     bx, bx                          ; zero out our flags
  69.         mov     si, offset buffer               ; pointer into file buffer
  70.         mov     di, offset pr_buff              ; pointer into printer string
  71.  
  72. disp2:  mov     al, byte ptr ds:[si]
  73.         cmp     al, '<'                         ; is it a start char?
  74.         jne     disp3                           ; no, process it further
  75.         mov     bh, 1                           ; yes, set flag
  76.         jmp     short disp6                     ; get another
  77.  
  78. disp3:  cmp     bh, 0                           ; is flag set?
  79.         je      disp6                           ; no, skip this one
  80.         cmp     al, '>'                         ; is it an end char?
  81.         jne     disp4                           ; no, see if length ok
  82.  
  83.         xor     bh, bh                          ; yes, turn off parser flag
  84.         cmp     bl, 0                           ; any valid chars?
  85.         je      abort                           ; no, flag it as error
  86.  
  87.         call    print                           ; try to send it to printer
  88.         xor     bl, bl                          ;  reset length counter
  89.         mov     di, offset pr_buff              ;   reset pointer to output
  90.         jmp     short disp6                     ;    and back for more
  91.  
  92. disp4:  inc     bl                              ; bump up length counter
  93.         cmp     bl, 3                           ; max length allowed
  94.         ja      abort                           ; no good, skip num test
  95.  
  96.         cmp     al, '0'                         ; check for valid numeric
  97.         jb      abort
  98.         cmp     al, '9'
  99.         ja      abort                           ; not numeric, abort
  100.  
  101.         jmp     short disp5                     ; ok, let this one through
  102.  
  103. abort:  mov     al, 1                           ; no good, abort
  104.         jmp     short exit                      ; and back to DOS
  105.  
  106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  107. ; build up printer output string
  108. ;
  109. disp5:  mov     dl, al                          ; got a live one here
  110.         sub     dl, '0'                         ; convert to binary
  111.         mov     byte ptr ds:[di], dl            ; stick it in print buffer
  112.         inc     di                              ; bump up print buffer pointer
  113.  
  114. disp6:  inc     si                              ; point to next byte
  115.         dec     cx                              ; unless end of buffer
  116.         jz      done                            ; end, done
  117.         jmp     disp2                           ; more, go get next byte
  118.  
  119.  
  120. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  121. done:   xor     al, al                          ; clear error, fall through
  122.  
  123.  
  124. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  125. ; general exit routine
  126. ;
  127. exit:   mov     ah, 4ch                         ; error code passed in al
  128.         int     21h
  129.  
  130.  
  131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  132. ; send codes to printer
  133. ;
  134. print:  push    dx
  135.         push    cx
  136.  
  137.         xor     dx, dx                          ; zero out output byte
  138.         dec     di                              ; last digit found
  139.  
  140.         mov     dl, byte ptr ds:[di]            ; get ones digit
  141.         dec     di
  142.         dec     bl
  143.         jz      pr_out
  144.  
  145.         mov     al, byte ptr ds:[di]            ; this is tens digit
  146.         mov     cl, 10
  147.         mul     cl
  148.         add     dl, al
  149.         dec     di                              ; back up again
  150.         dec     bl
  151.         jz      pr_out
  152.  
  153.         mov     al, byte ptr ds:[di]            ; this is hundreds digit
  154.         mov     cl, 100
  155.         mul     cl
  156.         jc      pr_val                          ; carry flag, error
  157.         add     dl, al
  158.         jc      pr_val                          ; check again after add
  159.  
  160. pr_out: mov     ah, 05h                         ; get ready to send
  161.         int     21h                             ; send out the value
  162.         jmp     short prexit                    ; and skip error routine
  163.  
  164. pr_val: mov     al, 1                           ; value-error handler
  165.         jmp     short exit                      ; abort to DOS
  166.  
  167. prexit: pop     cx
  168.         pop     dx
  169.         ret
  170.  
  171.  
  172. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  173. ; see if printer is ready
  174. ;
  175. pr_chk: xor     dx, dx                          ; default printer
  176.         mov     ah, 2                           ; printer status function
  177.         int     17h                             ; of bios printer services
  178.         cmp     ah, 10010000b                   ; printer on-line?
  179.         je      ck_ret                          ; yes, just return
  180.         mov     al, 1
  181.         jmp     short exit                      ; no, abort
  182. ck_ret: ret
  183.  
  184.  
  185. ;
  186. ;----------------------------------------------------------------------------
  187. ; data storage area
  188.  
  189. pr_buff db      3 dup(?)                        ; output to printer
  190. buffer  db      BSIZE dup (?)                   ; file i/o buffer
  191.  
  192. PRT     ENDS
  193.         END     START
  194.  
  195.